1842B - Tenzing and Books - CodeForces Solution


bitmasks greedy math

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

using namespace std;

#define _IO() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define int long long


int32_t main() {
    _IO();
    int t, casen = 1;
    cin >> t;
    while (t--) {
        int n, x;
        cin >> n >> x;

        vector<int> s1(n);
        vector<int> s2(n);
        vector<int> s3(n);

        for (int i = 0; i < n; i++) {
            cin >> s1[i];
        }

        for (int i = 0; i < n; i++) {
            cin >> s2[i];
        }

        for (int i = 0; i < n; i++) {
            cin >> s3[i];
        }

        int knowledge = 0;

        for (int i = 0; i < n; i++) {
            if ((x | s1[i]) == x) {
                knowledge |= s1[i];
            } else {
                break;
            }
        }

        for (int i = 0; i < n; i++) {
            if ((x | s2[i]) == x) {
                knowledge |= s2[i];
            } else {
                break;
            }
        }

        for (int i = 0; i < n; i++) {
            if ((x | s3[i]) == x) {
                knowledge |= s3[i];
            } else {
                break;
            }
        }

        if (knowledge == x) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}


Comments

Submit
0 Comments
More Questions

1263A - Sweet Problem
1332B - Composite Coloring
254A - Cards with Numbers
215A - Bicycle Chain
1288B - Yet Another Meme Problem
1201C - Maximum Median
435A - Queue on Bus Stop
1409B - Minimum Product
723B - Text Document Analysis
1471C - Strange Birthday Party
1199A - City Day
1334A - Level Statistics
67B - Restoration of the Permutation
1734A - Select Three Sticks
1734B - Bright Nice Brilliant
357B - Flag Day
937A - Olympiad
1075A - The King's Race
1734C - Removing Smallest Multiples
1004C - Sonya and Robots
922A - Cloning Toys
817A - Treasure Hunt
1136B - Nastya Is Playing Computer Games
1388A - Captain Flint and Crew Recruitment
592B - The Monster and the Squirrel
1081A - Definite Game
721C - Journey
1400A - String Similarity
1734E - Rectangular Congruence
1312D - Count the Arrays